package com.example.baozidemo.controller;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.baozidemo.dto.PlanCycleDto;
import com.example.baozidemo.entity.EaBrandEntity;
import com.example.baozidemo.entity.SysUserEntity;
import com.example.baozidemo.service.EaBrandService;
import com.example.baozidemo.service.SysUserService;
import com.example.baozidemo.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private EaBrandService eaBrandService;
    @RequestMapping("/aa")
    public String test()
    {
//        Map<String, Object> params=new HashMap<>();
//        params.put("userBucode", "1");
//        params.put("userCompanyCode", "2");
//        IPage<SysUserEntity> ipage=sysUserService.queryPage(params,true);
//
//        Map<String, List<SysUserEntity>> map=sysUserService.queryMapBy();
//        map.forEach((userName,sList) ->{
//            System.out.println(userName+":");
//            sList.stream().forEach(System.out::println);
//        });
//
//        return new PageData(ipage,SysUserEntity.class);
        //创建一个list
//        List<String> cycleDtoList = CollUtil.newArrayList("百事","百事","可口可乐","联合利华","联合利华","乐事");
        List<PlanCycleDto> cycleDtoList = CollUtil.newArrayList(
                new PlanCycleDto("1","2","百事"),
                new PlanCycleDto("1","3","百事"),
                new PlanCycleDto("1","4","可口可乐"),
                new PlanCycleDto("1","5","联合利华"),
                new PlanCycleDto("1","6","联合利华"),
                new PlanCycleDto("1","7","乐事")

        );
        List<String> brandNameList=cycleDtoList.parallelStream().map(PlanCycleDto::getBrandName).distinct().collect(Collectors.toList());
        brandNameList.forEach(t -> System.out.println(t));
        Map<String, List<EaBrandEntity>> brandMap = eaBrandService.queryListMapByBrandName(brandNameList);
        brandMap.forEach(
                (brandName,brand) ->{
                    System.out.println(brandName+ ":"+JSON.toJSONString(brand));
                }
        );

        return "访问成功!";
    }
}
